package com.alipay.app.groupmeal.standard.ui.b.util;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.alipay.app.groupmeal.standard.constant.BaseConstant;
import com.blankj.utilcode.util.SPUtils;

import java.math.BigDecimal;

/**
 * @ProjectName: 团餐
 * @ClassName: DeviceInfoManager
 * @Description: 设备相关信息
 * @Author: bd-001935
 * @CreateDate: 4/15/22 8:21 PM
 * @UpdateUser: bd-001935
 * @UpdateDate: 4/15/22 8:21 PM
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class DeviceInfoManager {

    //收银模式
    private static String cashierMode;

    //串口设备选择通讯
    private static String serialPortSelect;

    private static int serialPortNum;

    //是否启动时下载白名单；
    private static boolean autoDownFk;


    public static boolean isAutoDownFk() {
        autoDownFk = SPUtils.getInstance().getBoolean("autoDownFk", false);
        return autoDownFk;
    }

    public static void setAutoDownFk(boolean autoDownFk) {
        DeviceInfoManager.autoDownFk = autoDownFk;
        SPUtils.getInstance().put("autoDownFk", autoDownFk);
    }

    public static void swAutoDownFk(){
        SPUtils.getInstance().put("autoDownFk", !DeviceInfoManager.autoDownFk);
    }

    public static String getCashierMode() {
        cashierMode = SPUtils.getInstance().getString("cashierMode", "");
        //默认收银模式
        if (TextUtils.isEmpty(cashierMode)) {
            cashierMode = BaseConstant.CASHIER_MODE.MODE_FREE;
            setCashierMode(cashierMode);
        }
        return cashierMode;
    }

    public static void setCashierMode(String cashierMode) {
        DeviceInfoManager.cashierMode = cashierMode;
        SPUtils.getInstance().put("cashierMode", cashierMode);
    }

    public static String getSerialPortSelect() {
        serialPortSelect = SPUtils.getInstance().getString("serialPort", "");
        return serialPortSelect;
    }

    public static void setSerialPortSelect(String serialPortSelect) {
        DeviceInfoManager.serialPortSelect = serialPortSelect;
        SPUtils.getInstance().put("serialPort", serialPortSelect);
    }

    public static int getSerialPortNum() {
        serialPortNum = SPUtils.getInstance().getInt("serialPortNum", 0);
        return serialPortNum;
    }

    public static void setSerialPortNum(int serialPortNum) {
        DeviceInfoManager.serialPortNum = serialPortNum;
        SPUtils.getInstance().put("serialPortNum", serialPortNum);
    }

    public static double getFixedAmount() {
        return new BigDecimal(SPUtils.getInstance().getString("fixedAmount", "0")).doubleValue();
    }

    public static String getFixedAmountString() {
        return String.format("%.2f", getFixedAmount());
    }

    /**
     * 单位:分
     *
     * @param fixedAmount
     */
    public static void setFixedAmount(String fixedAmount) {
        SPUtils.getInstance().put("fixedAmount", fixedAmount);
    }

    /**
     * 是否配置过固定模式金额
     *
     * @return
     */
    public static boolean haveSetAmount() {
        return getFixedAmount() > 0;
    }

    public static String getICCID(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String iccid = "";
        try {
            iccid = telephonyManager.getSimSerialNumber();
        } catch (Exception e) {

        }
        return iccid;
    }

}
